package com.tongtong.middleware.blockchain.client.web3j;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;

@Configuration
@RefreshScope
@Data
public class WEB3JConfig {
    @Value("${eth.gateway}")
    private String gateway;

    Web3j web3jClient = null;

    public Web3j conn() {
        if (web3jClient == null) {
            web3jClient = Web3j.build(new HttpService(gateway));
        }
        return web3jClient;
    }
}
